<?php
class SetupController extends Controller{

    public $layout = 'main';
    public $defaultAction='admin';
    public $step1Url;
    public $step2Url;
    public $officeUrl;

    public function init(){
        parent::init();

        $this->step1Url=$this->createUrl('step1');
        $this->step2Url=$this->createUrl('step2');
        $this->officeUrl=Yii::app()->createUrl('acp');
    }

    public function actions(){
        return array(
            'captcha' => array(
                'class' => 'ext.widgets.captchaExtended.CaptchaExtendedAction',
                'mode' => $this->captchaMode,
            ),
        );
    }

    public function actionStep2(){
        $root=Yii::getPathOfAlias('webroot');
        $dir='/'.array_pop(explode('/',$root));
        $root=str_replace($dir,'',$root);
        
        $paths=array(
            'assets'=>$root.$dir.'/assets',
            'runtime'=>$root.$dir.'/protected/runtime',
            'themes'=>$root.$dir.'/themes',
            'images'=>$root.'/uploads/images',
            'medias'=>$root.'/uploads/medias',
            'data'=>$root.'/uploads/data',
            'data'=>$root.'/uploads/data/json',
            //'avatars'=>$root.'/uploads/avatars',
            'watermarks'=>$root.'/uploads/watermarks',
            'templates'=>$root.'/uploads/templates',
        );

        $this->render('setupSystem', array(
            'paths'=>$paths,
        ));
    }

    public function actionAdmin(){
        $model=new ConfigForm('register');
        $form=Yii::app()->request->getParam(get_class($model));
        if(!empty($form)){
            $model->attributes=$form;			
            if($model->validate()){
                $user=new User('webmasterRegister');
                $user->autoFill();
                //$user->attributes=$model->attributes;
                $user->language_=$model->language_;
                $user->email_=$model->email_;
                $user->username_=$model->username_;
                $user->password_=$model->password_;
                if($user->addRecord()){
                    $this->redirect(Yii::app()->createUrl('acp'));
                }else{
                    $model->addErrors($user->getErrors());
                }
            }
        }

        $this->render('configForm',array(
            'model' => $model,
            'formConfig' => array(
                'id' =>  $this->formId,
                'enableAjaxValidation' => true,
                'enableClientValidation' => true,
                'clientOptions' => array(
                    //'validateOnSubmit' => true,
                ),
                'focus' => array($model, 'name_'),
            ),
        ));
    }



    // Uncomment the following methods and override them if needed
    /*
    public function filters()
    {
            // return the filter configuration for this controller, e.g.:
            return array(
                    'inlineFilterName',
                    array(
                            'class'=>'path.to.FilterClass',
                            'propertyName'=>'propertyValue',
                    ),
            );
    }

    public function actions()
    {
            // return external action classes, e.g.:
            return array(
                    'action1'=>'path.to.ActionClass',
                    'action2'=>array(
                            'class'=>'path.to.AnotherActionClass',
                            'propertyName'=>'propertyValue',
                    ),
            );
    }
    */
}//end class